#pragma once
#include <iostream>
#include <string>
#include <cstdio>
#include <pthread.h>
typedef void*(*func_t)(void*);

class ThreadData
{
public:
    void* args_;
    std::string name_;
};


class Thread
{
public:
    Thread(int num,func_t callback,void* args)
    :func_(callback)
    {
        char nameBuffer[64];
        snprintf(nameBuffer,sizeof nameBuffer,"Thread--%d",num);
        tdata_.name_ = nameBuffer;
        tdata_.args_ = args;
    }

    void start()
    {
        pthread_create(&tid_,nullptr,func_,(void*)&tdata_);
    }

    void join()
    {
        pthread_join(tid_,nullptr);
    }

    std::string name()
    {
        return tdata_.name_;
    }
private:
    func_t func_;
    ThreadData tdata_;
    pthread_t tid_;
};